{include file="public/header" /}
<body>

<div class="page-group">
    <div class="page">
        <!-- 标题栏 -->
        <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left back">
                <span class="icon icon-left"></span>
                返回
            </a>
            <h1 class="title">登录</h1>
        </header>
        <!-- 内容区 start -->
        <div class="content login_bg">
            <div class="list-block">
                <ul style="opacity:0.8;margin-top: 150px;">
                    <!-- Text inputs -->
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="iconfont icon-icon_zhanghao"></i></div>
                            <div class="item-inner">
                                <div class="item-input">
                                    <input type="text" id="name" placeholder="请输入姓名">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="iconfont icon-password"></i></div>
                            <div class="item-inner">
                                <div class="item-input">
                                    <input type="password" id="password" placeholder="请输入密码">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="iconfont icon-codev"></i></div>
                            <div class="item-inner">
                                <div class="item-input" style="width: auto">
                                    <input type="text" id="code" style="width: 70%;float:left;" placeholder="请输入验证码">
                                    <img class="code" src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?r='+Math.random();" alt="点击更换验证码">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="iconfont icon-yonghuguanli"></i></div>
                            <div class="item-inner">
                                <div class="item-input">
                                        <input type="radio" name="identity" value="0" checked> 学员
                                        <input type="radio" name="identity" value="1"> 教练
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="content-block">
                <div class="row">
                    <div class="col-100"><a class="button button-fill button-big button-round">登录</a></div>
                </div>
            </div>
            <!-- 内容区 end -->
        </div>
    </div>
</div>
{include file="public/foot" /}
<!-- 默认必须要执行$.init(),实际业务里一般不会在HTML文档里执行，通常是在业务页面代码的最后执行 -->
<script>
    $('.button').click(function () {
        var parArr = {};
        parArr.name = $('#name').val();
        parArr.password = $('#password').val();
        parArr.code = $('#code').val();
        parArr.identity = $('input[name=identity]:checked').val();

        var regName =/^[\u4e00-\u9fa5]{2,4}$/;//正则验证姓名
        if(!regName.test(parArr.name)){
            $.alert('请输入正确的姓名！');
            $("#name").val('');
        }else if(parArr.password.trim() === '' || parArr.password.length < 6){
            $.alert('请输入正确的密码！');
            $("#password").val('');
        }else if(parArr.code.trim() === '' || parArr.code.length !== 4){
            $.alert('请输入正确的验证码！');
            $("#code").val('');
        }else {
            $.showPreloader();
            $.ajax({
                url : '{:url('/index/login/loginAjax')}',
                type : "post",
                dataType : "json",
                data : 'data='+JSON.stringify(parArr),
                success : function(data) {
                    $.hidePreloader();
                    var dataObj = eval('(' + data + ')');
                    if(200 == dataObj.code){
                        window.location.href = "loginAssign";
                    }else {
                        $.alert(dataObj.message);
                    }
                },
                error : function($data) {
                    console.log($data);
                    $.hidePreloader();
                    $.alert('请求失败，服务器异常！');
                }
            });
        }
    });
    $.init();
</script>
</body>

</html>